const db = require("../../models/index")
const MessageBoards = db.messageBoards

// 查询所有数据
exports.findAll = (req, res) => {
    MessageBoards.findAll().then((data) => {
        res.send({
            data: data,
            code: 101,
            msg: "查询成功"
        })
    }).catch(err => {
        console.log(err.message + "查询数据出错")
    })
}

// 创建留言板日志数据
exports.create = (req, res) => {
    const data = {
        title: req.body.title,
        content: req.body.content,
        avatar: req.body.avatar,
        LikeCount: req.body.LikeCount
    }

    MessageBoards.create(data).then(data => {
        if (data) {
            res.send(
                {
                    data: data,
                    code: 104,
                    message: "日志创建成功"
                }
            )
            console.log(data)
        } else {
            res.send(
                {
                    data: null,
                    code: 204,
                    message: "日志创建失败"
                }
            )
        }
    }).catch(err => {
        console.log(err.message + "创建数据出错")
    })
}